//
//  PsdCompViewController.m
//  hellomui
//
//  Created by zhangtao on 15/11/3.
//  Copyright © 2015年 zt.td. All rights reserved.
//

#import "PsdCompViewController.h"
#import "LoginAndRegistViewController.h"
@interface PsdCompViewController ()<UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *psd;
@property (weak, nonatomic) IBOutlet UITextField *againPsd;
@property (weak, nonatomic) IBOutlet UIView *psdView;
@property (weak, nonatomic) IBOutlet UIView *againPsdView;
@property (weak, nonatomic) IBOutlet UIButton *submit;

@end

@implementation PsdCompViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _psdView.layer.cornerRadius = _psdView.frame.size.width/60;
    _againPsdView.layer.cornerRadius = _psdView.frame.size.width/60;
    _submit.layer.cornerRadius = _psdView.frame.size.width/60;

    _psd.placeholder = @"请输入新密码" ;
   _againPsd.placeholder = @"确认新密码";
    _psd.secureTextEntry = YES;
    _againPsd.secureTextEntry = YES;
    
    // Do any additional setup after loading the view.
}
- (IBAction)back:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)submit:(id)sender {
    NSString *path = @"login/updatePwd";
    NSMutableDictionary *dics = [NSMutableDictionary dictionaryWithObjectsAndKeys:_phoneNum,@"mobile",_psd.text,@"password", nil];
    NSLog(@"%@",dics);
    NSDictionary *dic = @{@"mobile":_phoneNum,@"password":_psd.text};
    NSDictionary *dicVal = @{@"mobile":_phoneNum,@"password":_psd.text,@"bd_sig":[ToolObjc md5Str:dic]};
    
    
    
    [[HttpConnctionManager sharedInstance]requestParam:dicVal andUrl:path andSuccessedBlock:^(NSDictionary *succeedResult) {
        NSLog(@"%@",succeedResult);
        if ([[NSString stringWithFormat:@
             "%@",[succeedResult valueForKey:@"resCode"]]isEqualToString:@"0"]) {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"修改成功，返回登录界面重新登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alert show];
        }
    } andFailedBlock:^(AFHTTPRequestOperation *response, NSError *error) {
        
    }];
    
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            [self backToLogin];
            break;
            
        default:
            break;
    }
}
-(void)backToLogin{
    LoginAndRegistViewController *login = [self.storyboard instantiateViewControllerWithIdentifier:@"loginAndRegist"];
    [self presentViewController:login animated:NO completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
